package com.haixiaoke.saas.enterprise.contract.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.annotation.TenantScope;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.common.tenant.TenantContext;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.contract.domain.ContractTemplateField;
import com.haixiaoke.saas.contract.service.IContractTemplateFieldService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 合同模板默认字段Controller
 * 
 * @author panda
 * @date 2024-05-30
 */
@RestController
@RequestMapping("/enterprise/contract/contractTemplateField")
public class EnterpriseContractTemplateFieldController extends BaseController {
    @Autowired
    private IContractTemplateFieldService contractTemplateFieldService;

    /**
     * 查询合同模板默认字段列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:contractTemplateField:list')")
    @GetMapping("/page")
    public TableDataInfo page(ContractTemplateField contractTemplateField) {
        startPage();
        List<ContractTemplateField> list = contractTemplateFieldService.selectContractTemplateFieldList(contractTemplateField);
        return getDataTable(list);
    }

    /**
     * 查询合同模板默认字段列表
     */
    @GetMapping("/list")
    public AjaxResult list(ContractTemplateField contractTemplateField) {
        List<ContractTemplateField> list = contractTemplateFieldService.selectContractTemplateFieldList(contractTemplateField);
        return success(list);
    }

    /**
     * 获取合同模板默认字段详细信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:contractTemplateField:query')")
    @GetMapping(value = "/{contractTemplateId}")
    public AjaxResult getInfo(@PathVariable("contractTemplateId") Long contractTemplateId) {
        return success(contractTemplateFieldService.selectContractTemplateFieldByContractTemplateId(contractTemplateId));
    }

    /**
     * 新增合同模板默认字段
     */
    @PreAuthorize("@ss.hasPermi('enterprise:contractTemplateField:add')")
    @Log(title = "合同模板默认字段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContractTemplateField contractTemplateField) {
        return toAjax(contractTemplateFieldService.insertContractTemplateField(contractTemplateField));
    }

    /**
     * 修改合同模板默认字段
     */
    @PreAuthorize("@ss.hasPermi('enterprise:contractTemplateField:edit')")
    @Log(title = "合同模板默认字段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContractTemplateField contractTemplateField) {
        return toAjax(contractTemplateFieldService.updateContractTemplateField(contractTemplateField));
    }

    /**
     * 删除合同模板默认字段
     */
    @PreAuthorize("@ss.hasPermi('enterprise:contractTemplateField:remove')")
    @Log(title = "合同模板默认字段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{templateFieldIds}")
    public AjaxResult remove(@PathVariable Long[] templateFieldIds) {
        return toAjax(contractTemplateFieldService.deleteContractTemplateFieldByContractTemplateIds(templateFieldIds));
    }
}
